﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MLY.Bll
{
    public static class UploadLog
    {

        public static string getLastUpload(int OrganizationId)
        {
            string lastUpload = "20.3.2012 18:00";
            using (Dal.lqKbmDataContext dc = new MLY.Dal.lqKbmDataContext())
            {
                try
                {
                    DateTime ActualData =
                        (from l in dc.TableUploadsLogs
                         join u in dc.TableUsers on l.UserId equals u.UserId
                         where (u.OrganiztionId == OrganizationId) &&
                               (l.updated + l.received > 0)
                         orderby l.ActivityDate descending
                         select l.ActivityDate).FirstOrDefault();
                    if (ActualData != null && ActualData.Year > 2010)
                    {
                        lastUpload = Utils.ShowDatetime(ActualData);
                    }
                }
                catch { }
            }

            return lastUpload;
        }
    }
    
}